/*************************************************************************
	> File Name: 1.fork.c
	> Author: WangYiFei
	> Mail: 824537320@qq.com
	> Created Time: Sun 10 Jan 2021 05:30:01 PM CST
 ************************************************************************/
#include "head.h"
#include <sys/wait.h>
#include <stdlib.h>

int main() {
    pid_t pid;
    int status;
    int i;
    for (i = 0; i < 10; i++) {
        if ((pid = fork()) < 0) {
            perror("fork()");
            exit(1);
        }
        // if (pid == 0) {
        //     pid = getpid();
        //     printf("Child Process = %d, Process ID = %d\n", i, pid);
        //     return 0;
        // } else {
        //     // printf("Parent Process!\n");
        //     // pid = wait(&status);
        //     // printf("%d's Wait Status = %d\n", pid,  status);
        // }
        if (pid == 0) break; 
    }
    pid = getpid();
    printf("Child Process = %d, Process ID = %d\n", i, pid);
        
    return 0;
}
